package cn.tedu.array;//声明当前类所属的包名

public class ArryaDemo1 {
    public static void main(String[] args) {
//      二分查找
        //数组必须有序
        int[] arr = {3,15,20,36,88};
        //要查找的元素值
        int num = 65;

        //最大值 最小值下标
        int max = arr.length-1;
        int min = 0;
        //循环进行查找
        while(min<=max){
            //计算中间值的下标
            int mid = (min+max)/2;
            if(num==arr[mid]){
                System.out.println("找到了,下标为"+mid);
                break;
            }else if(num>arr[mid]){
                min = mid+1;
            }else{
                max = mid-1;
            }
        }
        if(min>max){
            System.out.println("没找到");
        }
    }
}
